package pers.lolicer.redtidelibrary.config

import android.content.Context
import android.graphics.Bitmap
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import pers.lolicer.redtidelibrary.R

object BitmapImageConfig{
    fun createBitmap(context: Context, resourceId: Int): ImageBitmap {
        val drawable = AppCompatResources.getDrawable(context, resourceId)
            ?: throw Exception("无法访问资源文件，APP可能遭到更改！")
        val bitmap = Bitmap.createBitmap(
            210,
            297,
            Bitmap.Config.ARGB_8888
        )
        // 创建Canvas并绘制Drawable到Bitmap
        val canvas = android.graphics.Canvas(bitmap)
        drawable.setBounds(0, 0, 210, 297)
        drawable.draw(canvas)

        return bitmap.asImageBitmap()
    }
}

